﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WSIMWindowsClient.WSIMProfile;

namespace WSIMWindowsClient
{
    public partial class UserSearch : Form
    {
        public UserSearch()
        {
            InitializeComponent();     
        }

        private void addThisContactToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            string group = "";                            
            group = toolStripTextBox1.Text;
            if(String.IsNullOrEmpty(group))
                group = "<default>";


            if (dgSearchResult.SelectedRows.Count > 0)
            {
                  ObjectFactory.GetProfileWS().AddContact(new AddContactRequest(
                    Int64.Parse(dgSearchResult.SelectedRows[0].Cells[0].Value.ToString()), group));
                  (MdiParent as MainForm).RefreshUserList();
            }
            
        }

        private void cmdFindContacts_Click(object sender, EventArgs e)
        {
            Criteria c = new Criteria();
            c.All = true;
            DataSet ds = ObjectFactory.GetProfileWS().UsersByCriteria(new UsersByCriteriaRequest(c)).UsersByCriteriaResult;
            dgSearchResult.DataSource = ds;
            dgSearchResult.DataMember = ds.Tables[0].TableName;
        }

        private void toolStripTextBox1_Click(object sender, EventArgs e)
        {
            toolStripTextBox1.Text = "";
        }
    }
}
